package edu.udel.mboch.towerdefense;

import java.util.ArrayList;

public class SplashTower extends Tower
{
	private static final long serialVersionUID = 6839873931992946698L;

	public SplashTower(Position position)
	{
		super(position, 4);
		damage = 15;
		speed = 2750;
		range = 4;
		cost = Tower.SPLASH_COST;
		name = "Splash Tower";
		timer = speed;
	}
	
	public SplashTower(Position position, ArrayList<Position> positionsInRange)
	{
		super(position, positionsInRange, 4);
		damage = 15;
		speed = 2500;
		range = 4;
		cost = Tower.SPLASH_COST;
		name = "Splash Tower";
	}

	public void shoot(TDState state)
	{
		if(timer>speed)
		{
			ArrayList<Mob> mobs = getMobsInRange(state);
			int min = Integer.MAX_VALUE;
			int minLoc = -1;
			if(mobs.size()>0)
			{
				for(int i = 0; i<mobs.size(); i++)
					if(mobs.get(i).getDistanceToEnd() < min)
					{
						min = mobs.get(i).getDistanceToEnd();
						minLoc = i;
					}
				state.getGrid().addProjectile(new Projectile(this, mobs.get(minLoc)));
			}
			if(mobs.size() > 0)
				while(timer>speed)
					timer%=speed;
		}
	}


	public Tower copy()
	{
		return new SplashTower(position.copy(), positionsInRange);
	}

	@Override
	public void print()
	{
		System.out.print("S");
	}

}
